"//\n"
"// Copyright (c) 2007 Niels Provos <provos@citi.umich.edu>\n"
"// All rights reserved.\n"
"//\n"
"var _timeout = null;\n"
"\n"
"function locationWithoutFragment() {\n"
"	var uri = top.location;\n"
"	return uri.toString().split('#')[0];\n"
"}\n"
"\n"
"function gotResult(req) {\n"
"	if (req.status != 200) {\n"
"		error_box(locationWithoutFragment());\n"
"		return;\n"
"	}\n"
"\n"
"	var response = req.responseXML;\n"
"	var danger = response.getElementsByTagName('danger')[0].firstChild.data;\n"
"	var complete = response.getElementsByTagName('complete')[0].firstChild.data;\n"
"\n"
"	// we only notify the user of dangerous crap\n"
"	if (danger == 'dangerous') {\n"
"		danger_box(locationWithoutFragment());\n"
"	} else if (complete == 'complete') {\n"
"		results_box(locationWithoutFragment());\n"
"	} else if (!complete || !danger) {\n"
"		error_box(locationWithoutFragment());\n"
"	}\n"
"}\n"
"\n"
"function launchCallback() {\n"
"	var req = new XMLHttpRequest();\n"
"	req.open('POST', '/_spybye_control_callback', true);\n"
"	req.onreadystatechange = function() {\n"
"		if (req.readyState == 4) {\n"
"			// Your callback code goes here\n"
"			gotResult(req);\n"
"		}\n"
"	}\n"
"	req.setRequestHeader('Content-Type',\n"
"	    'application/x-www-form-urlencoded');\n"
"	req.send('site=' + locationWithoutFragment());\n"
"}\n"
"\n"
"function changeBox(uri, message, color, backgroundColor) {\n"
"	var el = document.getElementById('spybye_box');\n"
"	if (!el)\n"
"		return null;\n"
"\n"
"	spybye_url = \"http://spybye/?url=\" + escape(uri) + \"&noiframe=1\";\n"
"\n"
"	// if the timeout is still pending then remove it\n"
"	if (_timeout) {\n"
"		clearTimeout(_timeout);\n"
"		_timeout = null;\n"
"	}\n"
"\n"
"	var inner_html = (\"<a href='http://spybye/'>o</a> \" + message +\n"
"	    \"<a style='color:'\" + color +\"' href='\" + spybye_url + \"' \" +\n"
"	    \"target='_blank' \" +\n"
"	    \"onclick=\\\"window.open('\" + spybye_url + \"', 'SpyBye Result', 'width=500,height=600,resizable=1,scrollbars=1'); \" +\n"
"	    \"return false\\\">\" + uri + \"</a>\" +\n"
"	    \"<span align=right style='position:absolute; right:20px; text-weight:bold;'>\" +\n"
"	    \"<a href='#' onclick='hideBox(); return false'>x</a></span>\");\n"
"\n"
"	el.style.display = 'block';\n"
"	el.style.backgroundColor = backgroundColor;\n"
"	el.style.color = color;\n"
"	el.innerHTML = inner_html;\n"
"\n"
"	return el\n"
"}\n"
"\n"
"function results_box(uri) {\n"
"	changeBox(uri, \"SpyBye has completed its analysis for \",\n"
"	    '#eeeeee', '#44aa33');\n"
"}\n"
"\n"
"function danger_box(uri) {\n"
"	changeBox(uri, \"Spybye has detected dangerous links on \",\n"
"	    '#112222', '#dd7766');\n"
"}\n"
"\n"
"function error_box(uri) {\n"
"	changeBox(uri, \"Spybye encountered an error analyzing \",\n"
"	    '#112222', '#dd7766');\n"
"}\n"
"\n"
"function hideBox() {\n"
"	var el = document.getElementById('spybye_box');\n"
"	if (!el)\n"
"		return;\n"
"\n"
"	el.style.display = 'none';\n"
"}\n"
"\n"
"function take_control() {\n"
"	document.write(\"<div id=spybye_box style='color:#eeeeee;font-size:14px;position:absolute; left:0px; top:0px; width:100%; background-color:#44aa33;clear:both;z-index:2147483647;font-family:arial,sans-serif;padding:4px;text-align:left;'>SpyBye running normally ... <span align=right style='position:absolute; right:20px; text-weight:bold;'><a href='#' onclick='hideBox(); return false'>x</a></span></div>\");\n"
"\n"
"	_lambda = function() {\n"
"		_timeout = null;\n"
"		hideBox();\n"
"	}\n"
"	_timeout = setTimeout(_lambda, 2000);\n"
"\n"
"	launchCallback();\n"
"}\n"
"\n"
"if (top.location == self.location)\n"
"	take_control();\n"
